package com.hdl.design.pattern;

import java.util.Scanner;

/**
 * 类名 SimpleFactoryDemo001
 * 描述 需要使用简单工厂，第一个需要优化的例子
 * 题目：控制台上输入两个数字和一个运算符，在控制台打印结果
 *
 * @author hedonglin
 * @version 1.0
 * @date 2019/9/6 21:59
 */
public class SimpleFactoryDemo001 {

    public static void main(String[] args) {
        System.out.println("请输入数字A:");
        Scanner scanner = new Scanner(System.in);
        double numA = scanner.nextDouble();

        System.out.println("请输入运算符:");
        scanner = new Scanner(System.in);
        String operate = scanner.next();

        System.out.println("请输入数字B:");
        scanner = new Scanner(System.in);
        double numB = scanner.nextDouble();

        double result = 0.0;
        if ("+".equals(operate)){
            result = numA + numB;
        }
        if ("-".equals(operate)){
            result = numA - numB;
        }
        if ("*".equals(operate)){
            result = numA * numB;
        }
        if ("/".equals(operate)){
            result = numA / numB;
        }

        System.out.println("结果是：" + result);
    }
}
